package org.phalanx.client.mapeditor;

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.Hashtable;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class PhalanxMapEditorStatusBar extends JPanel {
	JLabel coordinateTracker;
	JLabel informationLabel;
	Hashtable<String,String> informationTable;

	public PhalanxMapEditorStatusBar() {
		initializePanel();
		setUpComponents();
		setUpInformationTable();
		setUpQuickInfoPanel();
		setUpCoordinatePanel();
	}

	private void initializePanel() {
		this.setBackground(Color.black);
		this.setForeground(Color.white);
		this.setLayout(new GridBagLayout());
	}

	private void setUpComponents() {
		informationTable = new Hashtable<String,String>();
		coordinateTracker = new JLabel();
		coordinateTracker.setForeground(Color.white);
		setCoordinateTracker(0, 0);
		
		informationLabel = new JLabel();
		informationLabel.setForeground(Color.red);
	}
	
	private void setUpInformationTable(){
		informationTable.put(PhalanxMapEditorPanel.SELECTION_MODE, 
				"Select square(s) for information. Double click to center square");
		informationTable.put(PhalanxMapEditorPanel.ADDTILE_MODE,
				"Click on a square to add a tile, or drag for rectagle of tiles");
		informationTable.put(PhalanxMapEditorPanel.REMOVE_MODE,
		"Click on a square to revert tile to default tile");
		informationTable.put(PhalanxMapEditorPanel.BUILD_POINT_ADD_MODE,
		"Click on a square to add a player start point");
		informationTable.put(PhalanxMapEditorPanel.BUILD_POINT_DEL_MODE,
		"Click on a square to remove a player start point");
		informationTable.put(PhalanxMapEditorPanel.ZOOM_IN_MODE,
		"Click on an area to zoom in");
		informationTable.put(PhalanxMapEditorPanel.ZOOM_OUT_MODE,
		"Click on an area to zoom out");
		informationTable.put(PhalanxMapEditorPanel.NAV_MODE,
		"Click on an area to navigate to");
	}

	public void setCoordinateTracker(Integer x, Integer y) {
		coordinateTracker.setText("(" + x + "," + y + ")");
	}

	private void setUpCoordinatePanel() {
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 0;
		c.fill = GridBagConstraints.NONE;
		
		Container cont = new Container();
		cont.setBackground(Color.black);
		cont.setLayout(new FlowLayout(FlowLayout.CENTER));
		cont.add(coordinateTracker);
		

		this.add(cont, c);
	}
	
	private void setUpQuickInfoPanel(){
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 1;
		c.gridy = 0;
		c.fill = GridBagConstraints.HORIZONTAL;
		
		Container infoContainer = new Container();
		infoContainer.setBackground(Color.black);
		infoContainer.setLayout(new FlowLayout(FlowLayout.CENTER));
		infoContainer.add(informationLabel);
		
		//this.add(infoContainer,c);
	}
	
	public void setInformationStatus(String status){
		String infoText = informationTable.get(status);
		informationLabel.setText(infoText != null ? infoText : "");
	}
}
